package com.cmys.money.cloudshop.model.product;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "tb_producttype")
public class ProductType implements Serializable {

	private static final long serialVersionUID = 7726945106492194425L;

	/** 类别id **/
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(length = 20, nullable = false)
	private Long id;
	
	@Column(length = 20, nullable = false)
	private String code;

	/** 类别名称 **/
	@Column(length = 20, nullable = false)
	private String name;

	/** 备注，用于google搜索页面描述 **/
	@Column(length = 100, nullable = false)
	private String note;

	/** 是否可见 **/
	@Column(nullable = false)
	private Boolean visible;
	
	/** 排序 **/
	@Column(length = 20, nullable = false)
    private Long orderno;

	/** 子类别列表 **/
	@OneToMany(cascade = {CascadeType.REMOVE, CascadeType.REFRESH}, mappedBy = "parent", fetch = FetchType.LAZY)
	private List<ProductType> child = new ArrayList<ProductType>();

	/** 所属父类 **/
	@ManyToOne(cascade = CascadeType.REFRESH, optional = true, fetch = FetchType.EAGER)
	@JoinColumn(name = "parent_id")
	private ProductType parent;
	
	/** 产品 **/
	@OneToMany(cascade=CascadeType.ALL, mappedBy="productType", fetch=FetchType.LAZY)
	private List<ProductInfo> productInfos = new ArrayList<ProductInfo>();
	
	@Transient 
    private Boolean leaf;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public Boolean getVisible() {
		return visible;
	}

	public void setVisible(Boolean visible) {
		this.visible = visible;
	}

	public List<ProductType> getChild() {
		return child;
	}

	public void setChild(List<ProductType> child) {
		this.child = child;
	}

	public ProductType getParent() {
		return parent;
	}

	public void setParent(ProductType parent) {
		this.parent = parent;
	}

	public Boolean getLeaf() {
		return leaf;
	}

	public void setLeaf(Boolean leaf) {
		this.leaf = leaf;
	}
	
	public Long getOrderno() {
    	return orderno;
    }

	public void setOrderno(Long orderno) {
    	this.orderno = orderno;
    }

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public List<ProductInfo> getProductInfos() {
    	return productInfos;
    }

	public void setProductInfos(List<ProductInfo> productInfos) {
    	this.productInfos = productInfos;
    }

}
